<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>set的基本使用</title>
</head>
<body>
  
  <script>
    
   const set = new Set()
   console.log(set)

   set.add(1)
   set.add(2)
   set.add(3)
   set.add(4)
   console.log(set)

    // 3.应用场景: 数组的去重
    const names = ["abc", "cba", "nba", "cba", "nba"]

    const set1 = new Set(names)
    console.log(set1)
    const set2 = Array.from(set1) //转换成数组
    console.log(set2)

    // 4.Set的其他属性和方法
    set.delete(1)
    console.log(set)
    console.log(set.has(3))

    set.forEach(item => console.log(item))

      // 5.set支持for...of
      for (const item of set) {
      console.log(item)
    }

    
  </script>
</body>
</html>